package com.ruoyi.point.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.point.pojo.AlarmConfiguration;
import com.ruoyi.point.service.IAlarmConfigurationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 报警配置Controller
 *
 * @author ruoyi
 * @date 2024-04-22
 */
@RestController
@RequestMapping("/system/configuration")
public class AlarmConfigurationController extends BaseController
{
    @Autowired
    private IAlarmConfigurationService alarmConfigurationService;

    /**
     * 查询报警配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:list')")
    @GetMapping("/list")
    public TableDataInfo list(AlarmConfiguration alarmConfiguration)
    {
        startPage();
        List<AlarmConfiguration> list = alarmConfigurationService.selectAlarmConfigurationList(alarmConfiguration);
        return getDataTable(list);
    }

    /**
     * 导出报警配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:export')")
    @Log(title = "报警配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AlarmConfiguration alarmConfiguration)
    {
        List<AlarmConfiguration> list = alarmConfigurationService.selectAlarmConfigurationList(alarmConfiguration);
        ExcelUtil<AlarmConfiguration> util = new ExcelUtil<AlarmConfiguration>(AlarmConfiguration.class);
        util.exportExcel(response, list, "报警配置数据");
    }

    /**
     * 获取报警配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:query')")
    @GetMapping(value = "/{alarmConfigId}")
    public AjaxResult getInfo(@PathVariable("alarmConfigId") Long alarmConfigId)
    {
        return success(alarmConfigurationService.selectAlarmConfigurationByAlarmConfigId(alarmConfigId));
    }

    /**
     * 新增报警配置
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:add')")
    @Log(title = "报警配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AlarmConfiguration alarmConfiguration)
    {
        return toAjax(alarmConfigurationService.insertAlarmConfiguration(alarmConfiguration));
    }

    /**
     * 修改报警配置
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:edit')")
    @Log(title = "报警配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AlarmConfiguration alarmConfiguration)
    {
        return toAjax(alarmConfigurationService.updateAlarmConfiguration(alarmConfiguration));
    }

    /**
     * 删除报警配置
     */
    @PreAuthorize("@ss.hasPermi('system:configuration:remove')")
    @Log(title = "报警配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{alarmConfigIds}")
    public AjaxResult remove(@PathVariable Long[] alarmConfigIds)
    {
        return toAjax(alarmConfigurationService.deleteAlarmConfigurationByAlarmConfigIds(alarmConfigIds));
    }
}
